<?php

class ErrorController extends CustomControllerAction
{
    public function errorAction()
    {
        $request = $this->getRequest();

        $error = $request->getParam('error_handler');
        //echo $error->exception->getMessage();
        
        $headers= "MIME-Version: 1.0\r\n";
        $headers .= "Content-type: text/html; charset=utf-8\r\n";

        /* дополнительные шапки */
        $headers .= "From: Даба Handmade<notification@dabahm.com>\r\n";
        
        $emailTo = "stanislav.makushov@gmail.com, kuteiko@mail.ru";
        $emailSubject = "Системная ошибка на сайте Daba Handmade";
        
        $emailText = "На сайте Daba Handmade произошла ошибка. <br /><br />Текст ошибки: <b>" . $error->exception->getMessage() . "</b>";
        
        mail($emailTo, $emailSubject, $emailText, $headers);
        
        switch ($error->type) {
                case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
                case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
                    $this->_forward('error404');
                    return;

                case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_OTHER:
                default:
                    // fall through
            }

            $this->getResponse()->clearBody();
            
            Zend_Registry::get('logger')->crit($error->exception->getMessage());
    }
    
    public function error404Action()
        {
            $request = $this->getRequest();
            $error   = $request->getParam('error_handler');
            
            $uri     = $request->getRequestUri();

            Zend_Registry::get('logger')->info('возникла ошибка 404: ' . $uri);

            $this->getResponse()->setHttpResponseCode(404);
            
            $this->view->requestedAddress = $uri;
        }
}

?>
